package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

public class Test1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        List<Person> list = new ArrayList<>();
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class,int.class);
        for (int i=0;i<10;i++){
        String name = "Test"+(i+1);
        int age = 21+i;
        Object obj = c.newInstance(name,age);
            System.out.println(obj);
            list.add((Person)obj);
        }
        System.out.println(list);
    }
}
